<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page contentType="text/html; charset=UTF-8" %>
<%@ taglib uri="/struts-tags" prefix="s" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/sys/org/";  //应用的地址名
String actionName = "SysOrg";
if("dep".equals(request.getParameter("treeType")))  //根据treeType判断转向某个action
	actionName = "SysDep";
%>
<script type="text/javascript">

     $(function(){
         $('#orgManagerTree').tree({
				    url:'<%=path%>/util/util_getOrgTreeNodes.action?treeType=<%=request.getParameter("treeType") %>',  //获取json格式的节点树
				    //打开节点时的操作
				    onClick:function(node){
					    if(node.attributes.org&&node.state=='closed'){//加载下级节点
					    	$('#orgManagerTree').tree('expand',node.target);
					    }
					    $("#orgManager").load("<%=path%>/sys/org/<%=actionName%>_openViewPage.action?treeType=<%=request.getParameter("treeType") %>&vcId="+node.id+"&viewAreaName=orgManager&treeName=orgManagerTree");
				    },
				    onExpand:function(node){
				    	var ns = $('#orgManagerTree').tree('getChildren',node.target);
				    	if(ns.length==1&&ns[0].id=='tmp_loading'){//加载子节点
				    		$.getJSON('<%=path%>/util/util_getOrgTreeNodes.action?treeType=<%=request.getParameter("treeType") %>&pid='+node.id,function(data){
				    			$('#orgManagerTree').tree('remove',ns[0].target);
					    		if(data&&data.length>0){
				    				$('#orgManagerTree').tree('append',{parent:node.target,data:data[0].children});
					    		}
				    		});
				    	}
				    },
				    //加载数据失败的处理        
				    onLoadError: function () {    
				        $.messager.alert('消息提示','机构树加载失败，请稍后再试！','error'); 
				    }
				});
        });
 
</script>

<ul id="orgManagerTree"></ul>